package com.music.lib.qianqian.support;

import java.util.ArrayList;
import java.util.List;

/**
 * Jsoup Element support
 */
public class Elements extends ArrayList<Element>{

    private Object elements;

    Elements(Object elements){
        this.elements = elements;
        if(elements!=null){
            List<Object> list = (List<Object>) elements;
            list.stream().forEach(e->{
                add(new Element(e));
            });
        }
    }

    public String attr(String name){
        try {
            return (String) elements.getClass().getMethod("attr",new Class<?>[]{String.class}).invoke(elements,name);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public Element first(){
        try {
            Object o = elements.getClass().getMethod("first",null).invoke(elements,null);
            return new Element(o);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


}
